//
//  NewCareNewVC.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/7/6.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "NewCareNewVC.h"

#import "KSDatePicker.h"//rili

@interface NewCareNewVC ()
{
    UIView *oneView;
    UIView *twoView;
    UILabel *_birthLab;
    UILabel *_jieLab;
}

@property(nonatomic,strong)UISwitch *oneSwith;
@property(nonatomic,strong)UISwitch *twoSwith;

@end

@implementation NewCareNewVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"关怀";
    self.view.backgroundColor = BgColor;
    
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:self action:@selector(guanHuai)];
    rightBarItem.tintColor = [UIColor whiteColor];
    
    self.navigationItem.rightBarButtonItem = rightBarItem;
    [self.navigationItem.rightBarButtonItem setTitle:@"完成"];
    
    //客户生日关怀
    
    [self setupKeHuBirthday];
    //节日关怀
    [self setupFestival];
    
    
}

#pragma mark 客户生日关怀
-(void)setupKeHuBirthday
{
    
    oneView = [[UIView alloc]init];
    oneView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:oneView];
    [oneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(B_WIDTH, 100));
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(self.view.mas_top).offset(64);
        
    }];
    
    
    UIImageView *imgA = [[UIImageView alloc] init];
    imgA.image = [UIImage imageNamed:@"Care_birth"];
    [oneView addSubview:imgA];
    [imgA mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(25, 25));
        make.left.equalTo(oneView.mas_left).offset(25);
        make.top.equalTo(oneView.mas_top).offset(10);
    }];
    
    UILabel *oneLab = [[UILabel alloc] init];
    oneLab.text = @"客户生日关怀";
    oneLab.textColor = [UIColor orangeColor];
    oneLab.font = [UIFont systemFontOfSize:12];
    [oneView addSubview:oneLab];
    [oneLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(120, 20));
        make.left.mas_equalTo(imgA.mas_right).offset(10);
        make.top.equalTo(oneView.mas_top).offset(12);
  
        
    }];
    
    UILabel *twoLab = [[UILabel alloc] init];
    twoLab.text = @"默认在客户生日当天09:00提醒";
    twoLab.textColor = [UIColor blackColor];
    twoLab.font = [UIFont systemFontOfSize:10];
    [oneView addSubview:twoLab];
    [twoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(200, 20));
        make.left.mas_equalTo(oneView.mas_left).offset(30);
        make.top.equalTo(oneLab.mas_bottom).offset(5);
        
        
    }];

 
    _oneSwith = [[UISwitch alloc] init];
    //开关状态设置属性
    //YES:开启状态
    //NO:关闭状态
    _oneSwith.on=YES;
  
    //onTintColor处于on时switch 的颜色
    _oneSwith.onTintColor = [UIColor orangeColor];
    //tintColor处于off时switch 的颜色
    _oneSwith.tintColor = [UIColor grayColor];
     _oneSwith.transform = CGAffineTransformMakeScale( 0.8, 0.8);//缩放
    [_oneSwith addTarget:self action:@selector(oneSwitchBirth:) forControlEvents:UIControlEventValueChanged];
    [oneView addSubview:_oneSwith];
    [_oneSwith mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(40, 20));
        make.right.equalTo(oneView.mas_right).offset(-30);
        make.top.equalTo(oneView.mas_top).offset(15);
    }];
    
    
    UILabel *lineLab = [[UILabel alloc] init];
    lineLab.backgroundColor = [UIColor colorWithHexString:@"#d9d9d9"];
    [oneView addSubview:lineLab];
    [lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(B_WIDTH, 0.5f));
        make.centerX.equalTo(oneView.mas_centerX);
        make.top.mas_equalTo(twoLab.mas_bottom).offset(5);
        
    }];
    
    
    _birthLab = [[UILabel alloc] init];
    _birthLab.textColor = [UIColor orangeColor];
    _birthLab.text = @"2017/09/29";
    _birthLab.font = [UIFont systemFontOfSize:12];
    [oneView addSubview:_birthLab];
    [_birthLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(120, 20));
        make.left.mas_equalTo(oneView.mas_left).offset(30);
        make.top.equalTo(lineLab.mas_bottom).offset(8);
        
        
    }];
    
    UIButton *keBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [keBtn setBackgroundImage:[UIImage imageNamed:@"btnRiLi"] forState:0];
    keBtn.tag = 55;
    [keBtn addTarget:self action:@selector(birthdayGuanHuai:) forControlEvents:UIControlEventTouchUpInside];
    [oneView addSubview:keBtn];
    [keBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(30, 20));
        make.right.equalTo(oneView.mas_right).offset(-30);
        make.top.equalTo(lineLab.mas_bottom).offset(8);
    }];
   
}

#pragma mark 节日关怀
-(void)setupFestival
{
    twoView = [[UIView alloc]init];
    twoView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:twoView];
    [twoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(B_WIDTH, 100));
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.equalTo(oneView.mas_bottom).offset(10);
        
    }];
    
    
    UIImageView *imgA = [[UIImageView alloc] init];
    imgA.image = [UIImage imageNamed:@"Care_fesrival"];
    [twoView addSubview:imgA];
    [imgA mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(25, 25));
        make.left.equalTo(twoView.mas_left).offset(25);
        make.top.equalTo(twoView.mas_top).offset(10);
    }];
    
    UILabel *oneLab = [[UILabel alloc] init];
    oneLab.text = @"节日关怀";
    oneLab.textColor = [UIColor orangeColor];
    oneLab.font = [UIFont systemFontOfSize:12];
    [twoView addSubview:oneLab];
    [oneLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(120, 20));
        make.left.mas_equalTo(imgA.mas_right).offset(10);
        make.top.equalTo(twoView.mas_top).offset(12);
        
        
    }];
    
    UILabel *twoLab = [[UILabel alloc] init];
    twoLab.text = @"自定义设置日期定时提醒您跟进客户";
    twoLab.textColor = [UIColor blackColor];
    twoLab.font = [UIFont systemFontOfSize:10];
    [twoView addSubview:twoLab];
    [twoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(200, 20));
        make.left.mas_equalTo(twoView.mas_left).offset(30);
        make.top.equalTo(oneLab.mas_bottom).offset(5);
        
        
    }];
    _twoSwith = [[UISwitch alloc] init];
    //开关状态设置属性
    //YES:开启状态
    //NO:关闭状态
    _twoSwith.on=YES;
    
    //onTintColor处于on时switch 的颜色
    _twoSwith.onTintColor = [UIColor orangeColor];
    //tintColor处于off时switch 的颜色
    _twoSwith.tintColor = [UIColor grayColor];
    
    _twoSwith.transform = CGAffineTransformMakeScale( 0.8, 0.8);//缩放
    [_twoSwith addTarget:self action:@selector(twoSwitchOn:) forControlEvents:UIControlEventValueChanged];
    [twoView addSubview:_twoSwith];
    [_twoSwith mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(40, 20));
        make.right.equalTo(twoView.mas_right).offset(-30);
        make.top.equalTo(twoView.mas_top).offset(15);
    }];
    
    UILabel *lineLab = [[UILabel alloc] init];
    lineLab.backgroundColor = [UIColor colorWithHexString:@"#d9d9d9"];
    [twoView addSubview:lineLab];
    [lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(B_WIDTH, 0.5f));
        make.centerX.equalTo(twoView.mas_centerX);
        make.top.mas_equalTo(twoLab.mas_bottom).offset(5);
        
    }];

    _jieLab = [[UILabel alloc] init];
    _jieLab.textColor = [UIColor orangeColor];
    _jieLab.text = @"2017/09/29";
    _jieLab.font = [UIFont systemFontOfSize:12];
    
    [twoView addSubview:_jieLab];
    [_jieLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(120, 20));
        make.left.mas_equalTo(oneView.mas_left).offset(30);
        make.top.equalTo(lineLab.mas_bottom).offset(8);
        
        
    }];
    
    UIButton *jieBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [jieBtn setBackgroundImage:[UIImage imageNamed:@"btnRiLi"] forState:0];
    jieBtn.tag = 56;
    [jieBtn addTarget:self action:@selector(birthdayGuanHuai:) forControlEvents:UIControlEventTouchUpInside];
    [twoView addSubview:jieBtn];
    [jieBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(30, 20));
        make.right.equalTo(twoView.mas_right).offset(-30);
        make.top.equalTo(lineLab.mas_bottom).offset(8);
    }];

}

#pragma mark 导航右侧完成的按钮
-(void)guanHuai
{
    [self.navigationController popViewControllerAnimated:NO];
}
#pragma mark 客户生日关怀----节日关怀-------日历按钮
-(void)birthdayGuanHuai:(UIButton *)btn
{
    KSDatePicker* picker = [[KSDatePicker alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 40, 300)];
    picker.appearance.radius = 5;
    
    //设置回调
    picker.appearance.resultCallBack = ^void(KSDatePicker* datePicker,NSDate* currentDate,KSDatePickerButtonType buttonType){
        
        if (buttonType == KSDatePickerButtonCommit) {
            
            NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
            [formatter setDateFormat:@"yyyy-MM-dd"];
            if (btn.tag == 55)
            {
                _birthLab.text = [formatter stringFromDate:currentDate];
            }
            if (btn.tag == 56)
            {
                _jieLab.text = [formatter stringFromDate:currentDate];

            }
    
        }
    };
    // 显示
    [picker show];

}


#pragma mark 客户生日关怀-----开关按钮
-(void)oneSwitchBirth:(UISwitch *)swi
{
    if (swi.on == YES)
    {
           NSLog(@"开关被打开");
    }
    else
    {
          NSLog(@"开关关闭");
    }
}


#pragma mark 节日关怀
-(void)twoSwitchOn:(UISwitch *)swith
{
    if (swith.on == YES)
    {
        NSLog(@"开关被打开");
    }
    else
    {
        NSLog(@"开关关闭");
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
